<?php

declare(strict_types=1);

namespace Core\Package\ElementPlus\FormCreate\FormItem;


/**
 * 未完成
 * Class Color
 */
class Select extends FormItemAbstract
{
    protected string $_type = 'select';


    protected array $_options = [];

    /**
     * 获取值类型
     * @return string
     */
    public function valueType(): string
    {
        return self::VALUE_TYPE_STRING;
    }


    public function defaultProps(): array
    {
        return [
            'multiple' => false,
            'filterable' => true,
            'placeholder' => ''
        ];
    }

    /**
     * Select constructor.
     * @param string $field
     * @param string $title
     * @param float|int|string|null $value
     */
    public function __construct(string $field, string $title, float|int|string|null $value = null)
    {
        $this->_title = $title;
        $this->_field = $field;
        $this->_value = $value;
    }


    /**
     * 设置数据
     * @param array $options
     * @return Select
     */
    public function options(array $options): Select
    {
        foreach ($options as &$item) {
            $item['value'] = strval($item['value']);
        }
        $this->_options = $options;
        return $this;
    }


    /**
     * 是否可过滤
     * @param bool $filterable
     * @return Select
     */
    public function filterable(bool $filterable): Select
    {
        return $this->props('filterable', $filterable);
    }


    /**
     * 输入提示
     * @param string $placeholder
     * @return Select
     */
    public function placeholder(string $placeholder): Select
    {
        return $this->props('placeholder', $placeholder);
    }
}